//
//  CPSCVideoFilterListCategoryCell.m
//  CPSCustomer
//
//  Created by codew on 9/1/21.
//  Copyright © 2021 dgg_hzk. All rights reserved.
//

#import "CPSCVideoFilterListCategoryCell.h"


@interface CPSCVideoFilterListCategoryCell ()

@property (nonatomic, strong) UIView * viewContent;
@property (nonatomic, strong) UILabel * lblContent;


@property (nonatomic, strong) UIView * viewEditContent;
@property (nonatomic, strong) UILabel * lblEdit;
@property (nonatomic, strong) UIImageView * imageViewEdit;

//&#xe1056;

@end

@implementation CPSCVideoFilterListCategoryCell




- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame])
    {
        [self initSubviews];
        [self makeContraints];
    }
    
    return self;
}



- (void)updateCellWithItem:(NSString *)item
{
    if (item.length != 0) {
        
        self.viewEditContent.hidden = YES;
        self.lblContent.text = item;
    }else{
        
        // 代表最后一个编辑
        self.viewEditContent.hidden = NO;
        self.lblContent.text = @"";
    }
    
   
}


#pragma mark--initUI

- (void)initSubviews {
    
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.viewContent];
    [self addSubview:self.lblContent];
    
    [self addSubview:self.viewEditContent];
    [self.viewEditContent addSubview:self.lblEdit];
    [self.viewEditContent addSubview:self.imageViewEdit];
    
    self.viewEditContent.hidden = YES;
}

- (void)makeContraints {
    
    [self.viewContent mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.bottom.right.mas_equalTo(0);
    }];
    [self.lblContent mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self.viewContent);
    }];
    
    
    //=====
    [self.viewEditContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(0);
    }];
    [self.lblEdit mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.viewEditContent);
        make.left.mas_equalTo(16);
        
//        make.centerX.equalTo(self.viewEditContent).offset(-6);
        
    }];
    [self.imageViewEdit mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.lblEdit.mas_right).offset(6);
        make.centerY.equalTo(self.viewEditContent);
        make.width.height.mas_equalTo(13);
    }];
}

#pragma mark - Getter Setter

- (UIView *)viewContent
{
    
    if (!_viewContent) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        view.layer.cornerRadius = 4;
        view.layer.masksToBounds = YES;
        
        _viewContent = view;
    }
    return _viewContent;
}




- (UILabel *)lblContent
{
    if (!_lblContent) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#999999"];
        lblZy.font = [UIFont systemFontOfSize:13 weight:1];
        lblZy.textAlignment = NSTextAlignmentCenter;
        
        _lblContent = lblZy;
    }
    
    return _lblContent;
}


- (UIView *)viewEditContent
{
    
    if (!_viewEditContent) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        view.layer.cornerRadius = 4;
        view.layer.masksToBounds = YES;
        
        _viewEditContent = view;
    }
    return _viewEditContent;
}


- (UILabel *)lblEdit
{
    if (!_lblEdit) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#4974F5"];
        lblZy.font = [UIFont systemFontOfSize:13 weight:1];
        lblZy.textAlignment = NSTextAlignmentCenter;
        lblZy.text = @"编辑";
        
        _lblEdit = lblZy;
    }
    
    return _lblEdit;
}

- (UIImageView *)imageViewEdit
{
    if (!_imageViewEdit) {
        
        UIImageView * imageViewIcon = [[UIImageView alloc] init];
        imageViewIcon.contentMode = UIViewContentModeScaleAspectFill;
        
        imageViewIcon.image = [UIImage imageNamed:@"dizhibianji"];
        _imageViewEdit = imageViewIcon;
    }
    return _imageViewEdit;
}


//计算文字宽度
+ (CGFloat)settingCollectionViewItemWidthBoundingWithText:(NSString *)text{
    
    CGRect titleRect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, 32)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}
                                          context:nil];
    
    CGFloat btnW = ceilf(titleRect.size.width);
    return btnW;
}

+ (CGFloat)widthCellWithTitle:(NSString *)title
{
    CGFloat marginLR = 16;
    CGFloat widthTitle = [self settingCollectionViewItemWidthBoundingWithText:title];
    
    CGFloat widthCell = marginLR + widthTitle + marginLR;
    
    return widthCell;
}
@end
